package com.hcbd.tdwt.util;

import java.lang.reflect.Method;

public class PropUtils {
    private static final Class<?> systemPropertiesClass;
    private static final Method getMethod;
    private static final Method setMethod;

    static {
        Class<?> clazz = null;
        Method get = null;
        Method set = null;
        try {
            clazz = Class.forName("android.os.SystemProperties");
            get = clazz.getMethod("get", String.class, String.class);
            set = clazz.getMethod("set", String.class, String.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        systemPropertiesClass = clazz;
        getMethod = get;
        setMethod = set;
    }

    public static String getProp(String key, String def) {
        String prop = "";
        try {
            if (getMethod != null) {
                prop = (String) getMethod.invoke(systemPropertiesClass, key, def);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return prop;
    }

    public static void setProp(String key, String value) {
        try {
            if (setMethod != null) {
                setMethod.invoke(systemPropertiesClass, key, value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
